{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "7ab9d212",
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import numpy as np\n",
    "import ast\n",
    "import re\n",
    "list_a=np.arange(22)\n",
    "p1=pd.read_csv(\"测试初始.csv\",low_memory=False,usecols=list_a)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "8ac71d46",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['']"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "topic=ast.literal_eval(p1[\"发布论文年份\"][1])\n",
    "topic"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "0c9e2665",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "\"'\""
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "p1[\"发布论文年份\"][11]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "458666f8",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "\"['', 'C语言程序设计', 'C语言必须知道的300个问题', 'C语言程序设计', 'SQL Server 实用教程', '写给大家看的 C 语言书', 'MySQL 实用教程', 'C语言开发入门及项目实战']\""
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "p1[\"图书名称\"][0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "b3e3f0eb",
   "metadata": {},
   "outputs": [],
   "source": [
    "t=ast.literal_eval(p1[\"图书名称\"][0])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "39d2cab3",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "list"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "type(t)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "46baf3f3",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "7"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(t)-1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "54167817",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "      学生  阅读情况  荣誉情况\n",
      "0      0     5     0\n",
      "1      1     0     1\n",
      "2      2     2     0\n",
      "3      3    10     0\n",
      "4      4     6     0\n",
      "..   ...   ...   ...\n",
      "795  795     4     1\n",
      "796  796    10     2\n",
      "797  797     0     0\n",
      "798  798    20     0\n",
      "799  799     0     0\n",
      "\n",
      "[800 rows x 3 columns]\n"
     ]
    }
   ],
   "source": [
    "import pandas as pd\n",
    "import numpy as np\n",
    "import ast\n",
    "import re\n",
    "list_a=np.arange(22)\n",
    "p1=pd.read_csv(\"测试初始.csv\",low_memory=False,usecols=list_a)\n",
    "library=[]\n",
    "for i in range(0,800):\n",
    "    dict={}\n",
    "    t=ast.literal_eval(p1[\"图书名称\"][i])\n",
    "    m=ast.literal_eval(p1[\"荣誉称号名称\"][i])\n",
    "    dict[\"学生\"]=i\n",
    "    dict[\"阅读情况\"]=len(t)-1\n",
    "    dict[\"荣誉情况\"]=len(m)-1\n",
    "    library.append(dict)\n",
    "df1=pd.DataFrame(library)\n",
    "print(df1)\n",
    "df1.to_csv(\"lib_repu_test.csv\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "67f3f67d",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "      学生  论文情况\n",
      "0      0     0\n",
      "1      1     0\n",
      "2      2     0\n",
      "3      3     0\n",
      "4      4     0\n",
      "..   ...   ...\n",
      "795  795     0\n",
      "796  796     0\n",
      "797  797     0\n",
      "798  798     0\n",
      "799  799     0\n",
      "\n",
      "[800 rows x 2 columns]\n",
      "      学生  论文情况\n",
      "0      0     0\n",
      "1      1     0\n",
      "2      2     0\n",
      "3      3     0\n",
      "4      4     0\n",
      "..   ...   ...\n",
      "795  795     0\n",
      "796  796     0\n",
      "797  797     0\n",
      "798  798     0\n",
      "799  799     0\n",
      "\n",
      "[800 rows x 2 columns]\n",
      "      学生  论文情况\n",
      "0      0     0\n",
      "1      1     0\n",
      "2      2     0\n",
      "3      3     0\n",
      "4      4     0\n",
      "..   ...   ...\n",
      "795  795     0\n",
      "796  796     0\n",
      "797  797     0\n",
      "798  798     0\n",
      "799  799     0\n",
      "\n",
      "[800 rows x 2 columns]\n",
      "{'学生': 18, '论文情况': 0}\n"
     ]
    }
   ],
   "source": [
    "firstyear=[]\n",
    "secondyear=[]\n",
    "thirdyear=[]\n",
    "# year=ast.literal_eval(p1[\"评定学年\"][0])\n",
    "# type=ast.literal_eval(p1[\"奖学金类型\"][0])\n",
    "# level=ast.literal_eval(p1[\"奖励等级\"][0])\n",
    "dict={}\n",
    "dict[\"学生\"]=0\n",
    "dict[\"论文情况\"]=0\n",
    "firstyear.append(dict)\n",
    "secondyear.append(dict)\n",
    "thirdyear.append(dict)\n",
    "for i in range(0,799):\n",
    "    topic=ast.literal_eval(p1[\"发布论文年份\"][i+1])\n",
    "    number=p1[\"Unnamed: 0\"]\n",
    "    num_topic1=0\n",
    "    num_topic2=0\n",
    "    num_topic3=0\n",
    "    firstdict={}\n",
    "    seconddict={}\n",
    "    thirddict={}\n",
    "    firstdict[\"学生\"]=number[i+1]\n",
    "    seconddict[\"学生\"]=number[i+1]\n",
    "    thirddict[\"学生\"]=number[i+1]\n",
    "    for j in range(0,len(topic)):\n",
    "        if topic[j]==\"2019\":\n",
    "#             firstdict[\"类型\"]=type[j]+level[j]\n",
    "            num_topic1=num_topic1+1\n",
    "#             firstyear.append(firstdict)\n",
    "        elif topic[j]==\"2020\":\n",
    "            \n",
    "            num_topic2=num_topic2+1\n",
    "#             secondyear.append(seconddict)\n",
    "        elif topic[j]==\"2021\": \n",
    "            \n",
    "            num_topic3=num_topic3+1\n",
    "#             thirdyear.append(thirddict)\n",
    "    firstdict[\"论文情况\"]=num_topic1\n",
    "    seconddict[\"论文情况\"]=num_topic2\n",
    "    thirddict[\"论文情况\"]=num_topic3\n",
    "    firstyear.append(firstdict)\n",
    "    secondyear.append(seconddict)\n",
    "    thirdyear.append(thirddict)\n",
    "df1=pd.DataFrame(firstyear)\n",
    "print(df1)\n",
    "df2=pd.DataFrame(secondyear)\n",
    "print(df2)\n",
    "df3=pd.DataFrame(thirdyear)\n",
    "print(df3)\n",
    "print(thirdyear[18])\n",
    "df1.to_csv(\"topic18-19_test1.csv\")\n",
    "df2.to_csv(\"topic19-20_test2.csv\")\n",
    "df3.to_csv(\"topic20-21_test3.csv\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "9afddedd",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
